//
//  ByServiceForInHospitalVC.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/12/11.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByServiceForInHospitalVC.h"

// view
#import "ByViewServiceForInHospitalSegment.h"       // 顶部segment
#import "ByViewServiceForInHospitalPrehandMoney.h"  // 预交付
#import "ByViewServiceForInHospitalDailyBill.h"     // 日清单

@interface ByServiceForInHospitalVC ()

@property (nonatomic, strong) ByViewServiceForInHospitalSegment *segment;
@property (nonatomic, strong) ByViewServiceForInHospitalPrehandMoney *prehandView;
@property (nonatomic, strong) ByViewServiceForInHospitalDailyBill *bill;
@property (nonatomic, strong) UIButton *commitButton;

@end

@implementation ByServiceForInHospitalVC

#pragma mark - 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"住院服务";
    
    [self addLeftBackBarButtonItem];
    
    [self createViews];
}

#pragma mark - 创建视图
- (void)createViews {
    
    __weak typeof(self) wself = self;
    _segment = [ByViewServiceForInHospitalSegment new];
    _segment.segmentSelectIndexBlock = ^(NSInteger index) {
        [wself segmentSelect:index];
    };
    [self.view addSubview:_segment];
    
    _commitButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _commitButton.backgroundColor = rgba(148, 214, 250, 1);
    [_commitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_commitButton addTarget:self action:@selector(commit) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_commitButton];
    
    _prehandView = [ByViewServiceForInHospitalPrehandMoney new];
    [self.view addSubview:_prehandView];
    
    _bill = [ByViewServiceForInHospitalDailyBill new];
    _bill.hidden = true;
    [self.view addSubview:_bill];
    
    [_segment mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(@0);
        make.height.equalTo(@80);
    }];
    [_bill mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(_segment.mas_bottom);
    }];
    [_prehandView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(_segment.mas_bottom);
    }];
    [_commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.height.equalTo(@40);
        if (@available(ios 11.0,*)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.equalTo(@0);
        }
    }];
}
#pragma mark - 点击事件
- (void)segmentSelect:(NSInteger)index {
    
    _prehandView.hidden = index != 0;
    _bill.hidden = index != 1;
    
    [_commitButton setTitle:index == 0 ? @"前往支付" : @"合计" forState:UIControlStateNormal];
}
- (void)commit {
    
    if ([_commitButton.titleLabel.text isEqualToString:@"前往支付"]) {
        [ByCoreToolAlert showOnlyText:@"前往支付"];
    } else {
        [ByCoreToolAlert showOnlyText:@"合计"];
    }
}



@end
